package com.estar.assistsurvy.adapter;

import java.util.ArrayList;

import com.bumptech.glide.Glide;
import com.estar.assistsurvy.R;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class FragmentAdapter extends PagerAdapter {

	private ArrayList<Integer> images;
	private ArrayList<View> views;
	private Context context;
	public FragmentAdapter(ArrayList<Integer> images, Context context) {
		super();
		this.images = images;
		this.context = context;
		views=new ArrayList<View>();
		for(int i=0;i<images.size();i++){
			View view=LayoutInflater.from(context).inflate(R.layout.viewpager_item, null);
			views.add(view);
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return images.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub
		return arg0 == arg1;
	}
	
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		// TODO Auto-generated method stub
		((ViewPager)container).removeView(views.get(position));
	}
	
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		// TODO Auto-generated method stub
		View view=views.get(position);
		ImageView imageview=(ImageView) view.findViewById(R.id.image);
		Glide.with(context)
		.load(images.get(position))
		.into(imageview);
		container.addView(view);
		return view;
	}

}
